﻿using Autofac;
using Autofac.Configuration;
using Identification.Importer.Core.Job;
using Microsoft.Extensions.Configuration;
using StackExchange.Redis;

namespace Identification.Importer.Core
{
    public class ServiceDependencyModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            // 注册autofac.json
            var config = new ConfigurationBuilder();
            // config.AddJsonFile comes from Microsoft.Extensions.Configuration.Json
            // config.AddXmlFile comes from Microsoft.Extensions.Configuration.Xml
            config.AddJsonFile("autofac.json");

            // Register the ConfigurationModule with Autofac.
            var module = new ConfigurationModule(config.Build());
            builder.RegisterModule(module);

            // Register job
            builder.RegisterAssemblyTypes(ThisAssembly)
                .AsClosedTypesOf(typeof(BaseProcessor<,>)).AsSelf();

            // Register redis client
            builder.Register(c => ConnectionMultiplexer.Connect(c.Resolve<ServiceSetting>().RedisServer));
        }
    }
}